Skip to content

Upcast rotated box transforms #9175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 14, 2025

Conversation

AntoineSimoulin
Copy link
Member

Summary

This pull request addresses an issue where performing certain operations on rotated bounding boxes in float16 format could lead to NaN values due to overflow.

Issue Details

The functions _xyxyxyxy_to_xywhr and _parallelogram_to_bounding_boxes involve squaring operations on bounding box coordinates. When using float16 precision, boxes with absolute coordinate values above 256 can result in overflow, as the square of 257 ($257^2 = 66,049$) exceeds the maximum representable value for float16 ($65,504 = (2−2^{−10}) \times 2^{15}$). This leads to unreliable results and NaN values in subsequent computations.

Solution

To address this issue, this PR ensures that the floating point data is upcast to at least float32 for these operations. This increases the maximum representable value, allowing support for box coordinates up to $\sqrt{2^{31} - 1} \approx 46,341$, which should be sufficient for all common computer vision applications.

Additional Improvements

Simplified code related to rotated bounding box conversion by removing unnecessary integer-to-float conversions.
Rotated Bounding Boxes should not be constructed with integer dtype, so these conversions were redundant.

Copy link

pytorch-bot bot commented Aug 11, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9175

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure

As of commit 5ec4903 with merge base c85f008 (image):

NEW FAILURE - The following job has failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the cla signed label Aug 11, 2025
Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for noticing the issue and for the fix @AntoineSimoulin . I left a comment below but I'll approve to unblock

@AntoineSimoulin AntoineSimoulin merged commit 8c9aaed into pytorch:main Aug 14, 2025
59 of 60 checks passed
Copy link

Hey @AntoineSimoulin!

You merged this PR, but no labels were added.
The list of valid labels is available at https://github.com/pytorch/vision/blob/main/.github/process_commit.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants